package com.rao.quartz.service.serviceImpl;

import com.rao.entity.User;
import com.rao.quartz.mapper.UserMapper;
import com.rao.quartz.service.serviceInterface.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: raoguang
 * @Date: 2022/05/25/22:48
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserServiceSecondImpl userServiceSecond;

    @Override
    public List<User> findAllUserInfo() {
        List<User> userInfo = userMapper.findAllUserInfo();
        if (userInfo != null) {
            return userInfo;
        }
        return null;
    }

    @Override
    public User findSingleUserInfo(String userId) {
        User userInfo = userMapper.findSingleUserInfo(userId);
        if (userId != null) {
            return userInfo;
        }
        return null;
    }

    @Override
    public boolean insertUserInfo(User userInfo) {
        return userMapper.insertUserInfo(userInfo);
    }

    @Override
    public boolean updateUserInfo(int userId, User userInfo) {
        return userMapper.updateUserInfo(userId, userInfo);
    }

    @Override
    public boolean deleteUserInfo(int userId) {
        return userMapper.deleteUserInfo(userId);
    }

    @Override
    @Transactional
    public User testTranstion() {
        //先修改name=“饶大大” pwd="1999"
        User user = new User();
        user.setId("1");
        user.setName("饶大大");
        user.setPwd("1999");
        //第一次修改
        updateUserInfo(Integer.parseInt(user.getId()), user);
        //让他运行出异常
        //int i=1/0;
        //第二次修改
        User user1 = new User();
        user1.setId("1");
        user1.setName("大大饶");
        user1.setPwd("9991");
        updateUserInfo(Integer.parseInt(user1.getId()), user1);
        return findSingleUserInfo(user.getId());
    }


    @Override
    //@Transactional
    public User methodA() {
        //先修改name=“饶大大” pwd="1999"
        User user = new User();
        user.setId("1");
        user.setName("饶00000");
        user.setPwd("00000");
        //第一次修改
        updateUserInfo(Integer.parseInt(user.getId()), user);
        methodB();

        return findSingleUserInfo(user.getId());
    }

    @Override
    @Transactional
    public User methodB() {
        //先修改name=“饶大大” pwd="1999"
        User user = new User();
        user.setId("1");
        user.setName("饶1111");
        user.setPwd("111111");
        //第一次修改
        updateUserInfo(Integer.parseInt(user.getId()), user);
        userServiceSecond.methodC();
        return null;
    }


}
